package OptimalAlgorithm.Simulation;
//https://leetcode.cn/problems/teemo-attacking/
public class FindPoisonedDuration {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int totalTime = 0;
        int count = timeSeries.length;
        for (int i = 0; i < count; i++) {
            if(i + 1 < count && timeSeries[i + 1] >= timeSeries[i] + duration){
                totalTime += duration;
            }else if(i + 1 < count && timeSeries[i + 1] < timeSeries[i] + duration){
                totalTime += timeSeries[i + 1] - timeSeries[i];
            }
            if(i == count - 1){
                totalTime += duration;
            }
        }
        return totalTime;
    }
}
